/// @tags:
#include <cstdio>
#include <iostream>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int max1 = 0, max2 = 0, min1 = 0x3fffffff, min2 = 0x3fffffff;
    for (int i = 1, a; i <= n; ++i) {
      cin >> a;
      if (a >= max1) {
        max2 = max1, max1 = a;
      } else if (a > max2) {
        max2 = a;
      }
      if (a <= min1) {
        min2 = min1, min1 = a;
      } else if (a < min2) {
        min2 = a;
      }
    }
    cout << max1 + max2 - min1 - min2 << endl;
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("B_Interesting_Sum.in", "r", stdin);
  freopen("B_Interesting_Sum.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
